import {recipeData} from '../../common/recipeData.js'
import router from '@system.router';
import { jsCallJavaAbility } from '../../common/JsCallJavaAbilityUtils.js';
export default{
    data:{
        recipeData:recipeData,
        chooseId:0,
        text: "",
        iskey:0
    },
    onInit(){
        this.chooseId=this.pid;
        console.info( this.chooseId);
        console.info(recipeData[this.chooseId]);
    },
    cookClick(){
        router.push({
            uri:'pages/status/status',
            params:{status:this.recipeData[this.chooseId].pattern,arr:this.recipeData[this.chooseId].valueArr,rname:this.recipeData[this.chooseId].name},
        })
    },
    start() {
        jsCallJavaAbility.callAbility("ControllerAbility",100,{}).then(result=>{
            console.log(result)
        })
        console.info("开始")
    },
    stop() {
        jsCallJavaAbility.callAbility("ControllerAbility",101,{}).then(result=>{
            console.log(result)
        })
        jsCallJavaAbility.unSubAbility("ControllerAbility",201).then(result=>{
            if (result.code == 200) {
                console.log("取消订阅成功");
            }
        })
        console.info("停止")
    },
    sub() {
        jsCallJavaAbility.subAbility("ControllerAbility", 200, (data) => {
            let text = data.data.text

            text && (this.text += text)
            console.info(text)
            if(this.text.indexOf("准备好了")>-1){

                this.iskey=1;
                this.text=this.text.slice(0,this.text.length-4)
                this.cookClick()
            }

        }).then(result => {
            if (result.code == 200) {
                console.log("订阅成功");
            }
        })

    },
}